home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / fd2pragma / source / include / sdi_asm_std_protos.h < prev    next >
C/C++ Source or Header  |  2000-02-28  |  6KB  |  158 lines

  1. #ifndef SDI_ASM_STD_PROTOS_H
  2. #define SDI_ASM_STD_PROTOS_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        SDI_ASM_STD_protos
  7.     Versionstring:    $VER: SDI_ASM_STD_protos.h 1.19 (29.07.1998)
  8.     Author:        SDI
  9.     Distribution:    PD
  10.     Description:    my replacement for standard ANSI functions
  11.  
  12.  1.9   18.11.96 : converted text into english language, changed C++ comments
  13.      to C ones
  14.  1.10  29.11.96 : added printf
  15.  1.11  06.02.97 : added exit prototype
  16.  1.12  28.03.97 : added some additionally defines (AMIGA_TO_ANSI), added
  17.      vsprintf
  18.  1.13  31.05.97 : fixed SDI_isprintf
  19.  1.14  20.07.97 : changed UBYTE ** to STRPTR *
  20.  1.15  27.07.97 : fixed SDI_printf
  21.  1.16  20.02.98 : made code more compiler independent
  22.  1.17  25.02.98 : added vprintf
  23.  1.18  25.06.98 : now uses SDI_compiler.h
  24.  1.19  29.07.98 : isupper define was missing
  25. */
  26.  
  27. /* These are mainly the normal ANSI C functions, but with an ASM interface.
  28. You can replace them by their normal functions supplied with your compiler,
  29. but do not mix them up (one object file standard, the other one SDI).
  30.  
  31. differences:
  32.  toupper and tolower: chars (0x41 to 0x5A) and (0xC0 to 0xDE) are upper
  33.   chars (0x61 to 0x79) and (0xE0 to 0xFE) are lower (some more than in ANSI)
  34.  isprint: chars (0x20 to 0x7E) and (0xA0 to 0xFF) are printable
  35.  sprintf and printf: only support exec/RawDoFmt format strings
  36.   and some I do not remember.
  37.  strtoul and strtol: return NULL in errpos, when '\0'-Byte was last scanned
  38.   character. I do not know, if this is really correct for ANSI.
  39.  
  40.  all: return values may not match ANSI-C ones
  41.  
  42. printf: Use this function only for programs need to work under OS1.3. For
  43. OS2.0 (and up) programs should use dos.library/amiga.lib Printf function.
  44. */
  45.  
  46. #if defined(SDI_TO_ANSI) && defined(__GNUC__)
  47.   #include <string.h>
  48.   #include <stdlib.h>
  49.   #include <stdio.h>
  50.   #include <ctype.h>
  51. #else
  52.  
  53. #include <exec/types.h>
  54. #include "SDI_defines.h"
  55. #include "SDI_compiler.h"
  56.  
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60.  
  61. ASM(BYTE) SDI_strnicmp(    REG(a0,STRPTR),        /* string 1            */
  62.             REG(a1,STRPTR),        /* string 2            */
  63.             REG(d1,ULONG));        /* highest testlength        */
  64. ASM(BYTE) SDI_strncmp(    REG(a0,STRPTR),        /* string 1            */
  65.             REG(a1,STRPTR),        /* string 2            */
  66.             REG(d1,ULONG));        /* highest testlength        */
  67. ASM(UBYTE) SDI_tolower(    REG(d0,UBYTE));        /* character to convert        */
  68. ASM(UBYTE) SDI_toupper(    REG(d0,UBYTE));        /* character to convert        */
  69. ASM(ULONG) SDI_strlen (    REG(a0,STRPTR));    /* string            */
  70. ASM(ULONG) SDI_isprint(    REG(d0,UBYTE));        /* character to convert        */
  71. ASM(ULONG) SDI_isdigit(    REG(d0,UBYTE));        /* character to convert        */
  72. ASM(ULONG) SDI_isxdigit(REG(d0,UBYTE));        /* character to convert        */
  73. ASM(ULONG) SDI_isalnum(    REG(d0,UBYTE));        /* character to convert        */
  74. ASM(ULONG) SDI_isupper(    REG(d0,UBYTE));        /* character to convert        */
  75. ASM(ULONG) SDI_strtoul(    REG(a1,STRPTR),        /* buffer            */
  76.             REG(a0,STRPTR *),    /* UBYTE var for error position    */
  77.             REG(d2,UBYTE));     /* base                */
  78. ASM(ULONG) SDI_strtol(    REG(a1,STRPTR),        /* buffer            */
  79.             REG(a0,STRPTR *),    /* UBYTE var for error position */
  80.             REG(d2,UBYTE));     /* base                */
  81. ASM(STRPTR) SDI_strncpy(REG(a1,STRPTR),        /* string 1            */
  82.             REG(a0,STRPTR),        /* string 2            */
  83.             REG(d1,ULONG));        /* highest copy number        */
  84. ASM(void) SDI_memset(    REG(a1,APTR),        /* buffer            */
  85.             REG(d0,UBYTE),        /* fill character        */
  86.             REG(d1,ULONG));        /* number of bytes        */
  87. ASM(STRPTR) SDI_strchr(    REG(a1,STRPTR),        /* buffer            */
  88.             REG(d0,UBYTE));        /* character to scan for    */
  89. ASM(void) SDI_vsprintf(    REG(a3,STRPTR),        /* buffer            */
  90.             REG(a0,STRPTR),        /* formatstring            */
  91.             REG(a1,APTR));        /* data                */
  92. ASM(void) SDI_vprintf(    REG(a0,STRPTR),        /* formatstring            */
  93.             REG(a1,APTR));        /* data                */
  94. void SDI_sprintf(STRPTR, STRPTR, ...);        /* buffer, formatstring, data    */
  95. void SDI_printf(STRPTR, ...);            /* formatstring, data        */
  96.  
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100.  
  101. #define SDI_stricmp(a,b)    SDI_strnicmp(a,b,~0)
  102. #define SDI_strcmp(a,b)        SDI_strncmp(a,b,~0)
  103. #define SDI_strcpy(a,b)        SDI_strncpy(a,b,~0)
  104.  
  105. /* Set SDI_TO_ANSI if you want to use normal ANSI names. Do not include
  106. the ANSI files stdio.h / stdlib.h ... , because this may result in an error */
  107.  
  108. #ifdef SDI_TO_ANSI
  109.   #define strnicmp    SDI_strnicmp
  110.   #define strncmp    SDI_strncmp
  111.   #define stricmp    SDI_stricmp
  112.   #define strcmp    SDI_strcmp
  113.   #define tolower    SDI_tolower
  114.   #define toupper    SDI_toupper
  115.   #define strlen    SDI_strlen
  116.   #define isprint    SDI_isprint
  117.   #define isdigit    SDI_isdigit
  118.   #define isxdigit    SDI_isxdigit
  119.   #define isalnum    SDI_isalnum
  120.   #define isupper    SDI_isupper
  121.   #define strtoul    SDI_strtoul
  122.   #define strtol    SDI_strtol
  123.   #define strncpy    SDI_strncpy
  124.   #define strcpy    SDI_strcpy
  125.   #define strchr    SDI_strchr
  126.   #define memset    SDI_memset
  127.   #define sprintf    SDI_sprintf
  128.   #define printf    SDI_printf
  129.   #define vsprintf    SDI_vsprintf
  130.   #define vprintf    SDI_vprintf
  131.  
  132.   extern void exit(int);
  133. #endif
  134.  
  135. /* Use the following with care, as they may collide with ANSI-C Standard
  136.    a lot more, than the above ones. The FILE * parameter of the functions
  137.    is converted into a filehandle of dos.library. Do not mix normal ANSI-C
  138.    and these functions! */
  139.  
  140. /* These defines are in experimental state !!! */
  141.  
  142. #ifdef AMIGA_TO_ANSI
  143.   #define memcpy(a,b,c)        CopyMem(b,a,c)
  144.   #define remove(a)        !DeleteFile(a)
  145.   #define rename(a,b)        !Rename(a,b)
  146.   #define putchar(a)        FPutC(Output(),a)
  147.   #define putc(a, b)        FPutC((ULONG) b, a)
  148.   #define getchar()        FGetC(Input())
  149.   #define getc(a)        FGetC((ULONG) a)
  150.   #define ungetc(a,b)        UnGetC((ULONG) b,a)
  151.   #define vprintf(a,b)        VPrintf(a,b)
  152.   #define vfprintf(a,b,c)    VFPrintf((ULONG) a, b, c)
  153.   #define fclose(a)        Close(a)
  154. #endif
  155.  
  156. #endif /* SDI_TO_ANSI && __GNUC__ */
  157. #endif /* SDI_ASM_STD_PROTOS_H */
  158.